import { createApp } from "vue";
import "./style.css";
import './assets/main.css'
import App from "./App.vue";
import PiniaPluginPersistedstate from "pinia-plugin-persistedstate"
import naive from "naive-ui"; // 引入ui框架
import highlight from 'highlight.js'
import { createDiscreteApi } from "naive-ui"; // 引入createDiscreteApi
import { createPinia } from "pinia"; // 引入pinia
import { router } from "./common/router"; // 引入路由
import axios from "axios"; // 引入axios
import { UserStore } from "./stores/UserStore" // 引入UserStore
import "highlight.js/styles/atom-one-dark.css"
axios.defaults.baseURL = "http://120.46.13.13:8080"; // 服务端地址全局配置
const { message, notification, dialog } = createDiscreteApi(["message", "notification", "dialog"])

const app = createApp(App);

app.provide("axios", axios); // 将axios全局放入
app.provide("message", message)
app.provide("notification", notification)
app.provide("dialog", dialog)
app.provide("serverUrl", axios.defaults.baseURL)
const pinia = createPinia();
pinia.use(PiniaPluginPersistedstate);
app.use(pinia);
app.use(naive); // 引入ui框架


const userStore = UserStore()
// 拦截器传token
axios.interceptors.request.use((config) => {
    config.headers.authorization = `Bearer ${userStore.token}`
    return config
})


app.use(router); // 引入路由

// 配置Markdown语法高亮
app.directive("highlight",function(el){
    let blocks = el.querySelectorAll('pre code');
    blocks.forEach((block)=>{
      highlight.highlightBlock(block);
    })
  })
app.mount("#app");
